package com.boot.web.serviceImpl;

import com.boot.exception.BusinessException;
import com.boot.web.dao.SkuRelationDao;
import com.boot.web.dao.SkuSelectedDao;
import com.boot.web.dao.SpecAttributeDao;
import com.boot.web.dto.SpecTreeDTO;
import com.boot.web.entity.SkuRelation;
import com.boot.web.entity.SkuSelected;
import com.boot.web.entity.SpecAttribute;
import com.boot.web.vo.ProductVO;
import com.boot.web.vo.SpecTreeVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.boot.web.dao.ProductDao;
import com.boot.web.entity.Product;
import com.boot.web.service.ProductService;
import com.boot.base.serviceImpl.BaseServiceImpl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 产品业务层接口实现
 * @author 【zhouJie】
 * @date 2021-06-02 08:43:22
 */
@Service
public class ProductServiceImpl extends BaseServiceImpl<Product> implements ProductService {

    private static final Logger logger = LoggerFactory.getLogger(ProductServiceImpl.class);

    @Autowired
    private ProductDao productDao;

    @Autowired
    private SpecAttributeDao specAttributeDao;

    @Autowired
    private SkuSelectedDao skuSelectedDao;

    @Autowired
    private SkuRelationDao skuRelationDao;

    @Override
    public List<ProductVO> getProductVOPageList(Map<String, Object> map) {
        return productDao.queryProductVOPageList(map);
    }

    @Override
    public List<SpecTreeVO> getSpecAttributeTree(String classifyIdAndProductId) {
        String[] strings = classifyIdAndProductId.split("_");
        Integer classifyId = Integer.parseInt(strings[0]);
        Integer productId = Integer.parseInt(strings[1]);
        List<SpecAttribute> specAttributeList = specAttributeDao.querySpecAttributeTree(classifyId);
        List<SpecTreeVO> treeVOList = new ArrayList<>();
        if(specAttributeList.size() > 0){
            for(SpecAttribute sp : specAttributeList){
                SpecTreeVO treeVO = new SpecTreeVO();
                treeVO.setId(sp.getId());
                treeVO.setTitle(sp.getSpecName());
                treeVO.setExpand(true);
                treeVO.setParentId(sp.getParentId());

                SkuSelected skuSelected = skuSelectedDao.querySkuSelectedByProductId(productId);
                if(skuSelected != null){
                    if(skuSelected.getSpecAttribute().contains(",")){
                        String[] strings1 = skuSelected.getSpecAttribute().split(",");
                        for(int t = 0; t < strings1.length; t++){
                            if(strings1[t].contains("+")){
                                String[] strings2 = strings1[t].split("\\+");
                                if(Integer.parseInt(strings2[0]) == sp.getId()){
                                    //treeVO.setSelected(true);
                                    treeVO.setChecked(true);
                                }
                            }
                        }
                    }else{
                        if(skuSelected.getSpecAttribute().contains("+")){
                            String[] strings2 = skuSelected.getSpecAttribute().split("\\+");
                            if(Integer.parseInt(strings2[0]) == sp.getId()){
                                //treeVO.setSelected(true);
                                treeVO.setChecked(true);
                            }
                        }
                    }
                }

                List<SpecAttribute> spList = specAttributeDao.querySpecAttributeByParentId(sp.getId());
                if(spList.size() > 0){
                    List<SpecTreeVO> treeVOList1 = new ArrayList<>();
                    for(SpecAttribute sp1 : spList){
                        SpecTreeVO treeVO1 = new SpecTreeVO();
                        treeVO1.setId(sp1.getId());
                        treeVO1.setTitle(sp1.getAttributeName());
                        treeVO1.setExpand(true);
                        treeVO1.setParentId(sp1.getParentId());

                        if(skuSelected != null) {
                            if(skuSelected.getSpecAttribute().contains(",")){
                                String[] strings1 = skuSelected.getSpecAttribute().split(",");
                                for(int t = 0; t < strings1.length; t++){
                                    if(strings1[t].contains("+")){
                                        String[] strings2 = strings1[t].split("\\+");
                                        if(strings2[1].contains("_")){
                                            String[] strings3 = strings2[1].split("_");
                                            for(int m = 0; m < strings3.length; m++){
                                                if(Integer.parseInt(strings3[m]) == sp1.getId()){
                                                    //treeVO1.setSelected(true);
                                                    treeVO1.setChecked(true);
                                                }
                                            }
                                        }
                                    }
                                }
                            }else{
                                if(skuSelected.getSpecAttribute().contains("+")){
                                    String[] strings2 = skuSelected.getSpecAttribute().split("\\+");
                                    if(strings2[1].contains("_")){
                                        String[] strings3 = strings2[1].split("_");
                                        for(int m = 0; m < strings3.length; m++){
                                            if(Integer.parseInt(strings3[m]) == sp1.getId()){
                                                //treeVO1.setSelected(true);
                                                treeVO1.setChecked(true);
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        treeVOList1.add(treeVO1);
                        treeVO.setChildren(treeVOList1);
                    }
                }
                treeVOList.add(treeVO);
            }
        }
        return treeVOList;
    }

    //选择排序算法
    public static void selectionSort(int[] arr) {
        int min, temp;
        for (int i = 0; i < arr.length; i++) {
            // 初始化未排序序列中最小数据数组下标
            min = i;
            for (int j = i+1; j < arr.length; j++) {
                // 在未排序元素中继续寻找最小元素，并保存其下标
                if (arr[j] < arr[min]) {
                    min = j;
                }
            }
            // 将未排序列中最小元素放到已排序列末尾
            temp = arr[min];
            arr[min] = arr[i];
            arr[i] = temp;
        }
    }

    @Override
    public void submitSpecAttribute(SpecTreeDTO specTreeDTO) {
        String[] parentIds = specTreeDTO.getParentIds().split(",");
        // 顺序不能变动
        int[] arr = new int[parentIds.length];
        for(int c = 0; c < parentIds.length; c++){
            arr[c] = Integer.parseInt(parentIds[c]);
        }
        selectionSort(arr);
        // 顺序不能变动
        String[] ids = specTreeDTO.getIds().split(",");
        int[] arr1 = new int[ids.length];
        for(int c1 = 0; c1 < ids.length; c1++){
            arr1[c1] = Integer.parseInt(ids[c1]);
        }
        selectionSort(arr1);
        // 1+2_3,4+5
        String a = "";
        for(int i = 0; i < arr.length; i++){
            String specAttribute = String.valueOf(arr[i]);
            List<SpecAttribute> spList = specAttributeDao.querySpecAttributeByParentId(arr[i]);
            String s = "";
            for(SpecAttribute sp : spList){
//                String[] ids = specTreeDTO.getIds().split(",");
                for(int j = 0; j < arr1.length; j++){
                    if(sp.getId() == arr1[j]){
                        s += arr1[j] + "_";
                    }
                }
            }
            // 顺序不能变动
            specAttribute = specAttribute + "+" + s;
            specAttribute = specAttribute.substring(0, specAttribute.length() - 1);
            a += specAttribute + ",";
        }
        a = a.substring(0, a.length() - 1);
        SkuSelected skuSelected1 = skuSelectedDao.querySkuSelectedByIds(specTreeDTO.getProductId(), a);
        if(skuSelected1 != null){
            throw new BusinessException("当前产品配置的规格属性已存在，不可重复配置");
        }
        SkuSelected skuSelected = new SkuSelected();
        skuSelected.setProductId(specTreeDTO.getProductId());
        skuSelected.setSpecAttribute(a);
        skuSelected.setUpdateTime(new Date());
        skuSelectedDao.save(skuSelected);

        String sku = skuSelected.getSpecAttribute();
        if(sku.contains(",")){
            String[] skus = sku.split(",");
            int skusLength = skus.length;
            if(skusLength == 1){
                String spec1 = skus[0];
                if(spec1.contains("+")){
                    String[] specs1 = spec1.split("\\+");
                    String sp1 = specs1[1];
                    if(sp1.contains("_")){
                        String[] ss1 = sp1.split("_");
                        for(int z1 = 0; z1 < ss1.length; z1++){
                            String s1 = ss1[z1];
                            SkuRelation skuRelation = new SkuRelation();
                            skuRelation.setProductId(skuSelected.getProductId());
                            skuRelation.setGroupRelation(s1);
                            skuRelation.setUpdateTime(new Date());
                            skuRelation.setCostPrice(new BigDecimal(0));
                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                            skuRelation.setRetailPrice(new BigDecimal(0));
                            skuRelation.setParentProfit(new BigDecimal(0));
                            skuRelation.setAnchorProfit(new BigDecimal(0));
                            skuRelation.setMaximum(1);
                            skuRelation.setMinimum(1);
                            skuRelationDao.save(skuRelation);
                        }
                    }else{
                        SkuRelation skuRelation = new SkuRelation();
                        skuRelation.setProductId(skuSelected.getProductId());
                        skuRelation.setGroupRelation(sp1);
                        skuRelation.setUpdateTime(new Date());
                        skuRelation.setCostPrice(new BigDecimal(0));
                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                        skuRelation.setRetailPrice(new BigDecimal(0));
                        skuRelation.setParentProfit(new BigDecimal(0));
                        skuRelation.setAnchorProfit(new BigDecimal(0));
                        skuRelation.setMaximum(1);
                        skuRelation.setMinimum(1);
                        skuRelationDao.save(skuRelation);
                    }
                }
            }else if(skusLength == 2){
                String spec1 = skus[0];
                if(spec1.contains("+")){
                    String[] specs1 = spec1.split("\\+");
                    String sp1 = specs1[1];
                    if(sp1.contains("_")){
                        String[] ss1 = sp1.split("_");
                        for(int z1 = 0; z1 < ss1.length; z1++){
                            String s1 = ss1[z1];
                            String spec2 = skus[1];
                            if(spec2.contains("+")){
                                String[] specs2 = spec2.split("\\+");
                                String sp2 = specs2[1];
                                if(sp2.contains("_")){
                                    String[] ss2 = sp2.split("_");
                                    for(int z2 = 0; z2 < ss2.length; z2++){
                                        String s2 = ss2[z2];
                                        SkuRelation skuRelation = new SkuRelation();
                                        skuRelation.setProductId(skuSelected.getProductId());
                                        skuRelation.setGroupRelation(s1 + "," + s2);
                                        skuRelation.setUpdateTime(new Date());
                                        skuRelation.setCostPrice(new BigDecimal(0));
                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                        skuRelation.setParentProfit(new BigDecimal(0));
                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                        skuRelation.setMaximum(1);
                                        skuRelation.setMinimum(1);
                                        skuRelationDao.save(skuRelation);
                                    }
                                }else{
                                    SkuRelation skuRelation = new SkuRelation();
                                    skuRelation.setProductId(skuSelected.getProductId());
                                    skuRelation.setGroupRelation(s1 + "," + sp2);
                                    skuRelation.setUpdateTime(new Date());
                                    skuRelation.setCostPrice(new BigDecimal(0));
                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                    skuRelation.setParentProfit(new BigDecimal(0));
                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                    skuRelation.setMaximum(1);
                                    skuRelation.setMinimum(1);
                                    skuRelationDao.save(skuRelation);
                                }
                            }
                        }
                    }else{
                        String spec2 = skus[1];
                        if(spec2.contains("+")){
                            String[] specs2 = spec2.split("\\+");
                            String sp2 = specs2[1];
                            if(sp2.contains("_")){
                                String[] ss2 = sp2.split("_");
                                for(int z2 = 0; z2 < ss2.length; z2++){
                                    String s2 = ss2[z2];
                                    SkuRelation skuRelation = new SkuRelation();
                                    skuRelation.setProductId(skuSelected.getProductId());
                                    skuRelation.setGroupRelation(sp1 + "," + s2);
                                    skuRelation.setUpdateTime(new Date());
                                    skuRelation.setCostPrice(new BigDecimal(0));
                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                    skuRelation.setParentProfit(new BigDecimal(0));
                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                    skuRelation.setMaximum(1);
                                    skuRelation.setMinimum(1);
                                    skuRelationDao.save(skuRelation);
                                }
                            }else{
                                SkuRelation skuRelation = new SkuRelation();
                                skuRelation.setProductId(skuSelected.getProductId());
                                skuRelation.setGroupRelation(sp1 + "," + sp2);
                                skuRelation.setUpdateTime(new Date());
                                skuRelation.setCostPrice(new BigDecimal(0));
                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                skuRelation.setRetailPrice(new BigDecimal(0));
                                skuRelation.setParentProfit(new BigDecimal(0));
                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                skuRelation.setMaximum(1);
                                skuRelation.setMinimum(1);
                                skuRelationDao.save(skuRelation);
                            }
                        }
                    }
                }
            }else if(skusLength == 3){
                String spec1 = skus[0];
                if(spec1.contains("+")){
                    String[] specs1 = spec1.split("\\+");
                    String sp1 = specs1[1];
                    if(sp1.contains("_")){
                        String[] ss1 = sp1.split("_");
                        for(int z1 = 0; z1 < ss1.length; z1++){
                            String s1 = ss1[z1];
                            String spec2 = skus[1];
                            if(spec2.contains("+")){
                                String[] specs2 = spec2.split("\\+");
                                String sp2 = specs2[1];
                                if(sp2.contains("_")){
                                    String[] ss2 = sp2.split("_");
                                    for(int z2 = 0; z2 < ss2.length; z2++){
                                        String s2 = ss2[z2];
                                        String spec3 = skus[2];
                                        if(spec3.contains("+")){
                                            String[] specs3 = spec3.split("\\+");
                                            String sp3 = specs3[1];
                                            if(sp3.contains("_")){
                                                String[] ss3 = sp3.split("_");
                                                for(int z3 = 0; z3 < ss3.length; z3++){
                                                    String s3 = ss3[z3];
                                                    SkuRelation skuRelation = new SkuRelation();
                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                    skuRelation.setGroupRelation(s1 + "," + s2 + "," +s3);
                                                    skuRelation.setUpdateTime(new Date());
                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                    skuRelation.setMaximum(1);
                                                    skuRelation.setMinimum(1);
                                                    skuRelationDao.save(skuRelation);
                                                }
                                            }else{
                                                SkuRelation skuRelation = new SkuRelation();
                                                skuRelation.setProductId(skuSelected.getProductId());
                                                skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3);
                                                skuRelation.setUpdateTime(new Date());
                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                skuRelation.setMaximum(1);
                                                skuRelation.setMinimum(1);
                                                skuRelationDao.save(skuRelation);
                                            }
                                        }
                                    }
                                }else{
                                    String spec3 = skus[2];
                                    if(spec3.contains("+")){
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if(sp3.contains("_")){
                                            String[] ss3 = sp3.split("_");
                                            for(int z3 = 0; z3 < ss3.length; z3++){
                                                String s3 = ss3[z3];
                                                SkuRelation skuRelation = new SkuRelation();
                                                skuRelation.setProductId(skuSelected.getProductId());
                                                skuRelation.setGroupRelation(s1 + "," + sp2 + "," +s3);
                                                skuRelation.setUpdateTime(new Date());
                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                skuRelation.setMaximum(1);
                                                skuRelation.setMinimum(1);
                                                skuRelationDao.save(skuRelation);
                                            }
                                        }else{
                                            SkuRelation skuRelation = new SkuRelation();
                                            skuRelation.setProductId(skuSelected.getProductId());
                                            skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3);
                                            skuRelation.setUpdateTime(new Date());
                                            skuRelation.setCostPrice(new BigDecimal(0));
                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                            skuRelation.setParentProfit(new BigDecimal(0));
                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                            skuRelation.setMaximum(1);
                                            skuRelation.setMinimum(1);
                                            skuRelationDao.save(skuRelation);
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        String spec2 = skus[1];
                        if(spec2.contains("+")){
                            String[] specs2 = spec2.split("\\+");
                            String sp2 = specs2[1];
                            if(sp2.contains("_")){
                                String[] ss2 = sp2.split("_");
                                for(int z2 = 0; z2 < ss2.length; z2++){
                                    String s2 = ss2[z2];
                                    String spec3 = skus[2];
                                    if(spec3.contains("+")){
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if(sp3.contains("_")){
                                            String[] ss3 = sp3.split("_");
                                            for(int z3 = 0; z3 < ss3.length; z3++){
                                                String s3 = ss3[z3];
                                                SkuRelation skuRelation = new SkuRelation();
                                                skuRelation.setProductId(skuSelected.getProductId());
                                                skuRelation.setGroupRelation(sp1 + "," + s2 + "," +s3);
                                                skuRelation.setUpdateTime(new Date());
                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                skuRelation.setMaximum(1);
                                                skuRelation.setMinimum(1);
                                                skuRelationDao.save(skuRelation);
                                            }
                                        }else{
                                            SkuRelation skuRelation = new SkuRelation();
                                            skuRelation.setProductId(skuSelected.getProductId());
                                            skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3);
                                            skuRelation.setUpdateTime(new Date());
                                            skuRelation.setCostPrice(new BigDecimal(0));
                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                            skuRelation.setParentProfit(new BigDecimal(0));
                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                            skuRelation.setMaximum(1);
                                            skuRelation.setMinimum(1);
                                            skuRelationDao.save(skuRelation);
                                        }
                                    }
                                }
                            }else{
                                String spec3 = skus[2];
                                if(spec3.contains("+")){
                                    String[] specs3 = spec3.split("\\+");
                                    String sp3 = specs3[1];
                                    if(sp3.contains("_")){
                                        String[] ss3 = sp3.split("_");
                                        for(int z3 = 0; z3 < ss3.length; z3++){
                                            String s3 = ss3[z3];
                                            SkuRelation skuRelation = new SkuRelation();
                                            skuRelation.setProductId(skuSelected.getProductId());
                                            skuRelation.setGroupRelation(sp1 + "," + sp2 + "," +s3);
                                            skuRelation.setUpdateTime(new Date());
                                            skuRelation.setCostPrice(new BigDecimal(0));
                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                            skuRelation.setParentProfit(new BigDecimal(0));
                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                            skuRelation.setMaximum(1);
                                            skuRelation.setMinimum(1);
                                            skuRelationDao.save(skuRelation);
                                        }
                                    }else{
                                        SkuRelation skuRelation = new SkuRelation();
                                        skuRelation.setProductId(skuSelected.getProductId());
                                        skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3);
                                        skuRelation.setUpdateTime(new Date());
                                        skuRelation.setCostPrice(new BigDecimal(0));
                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                        skuRelation.setParentProfit(new BigDecimal(0));
                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                        skuRelation.setMaximum(1);
                                        skuRelation.setMinimum(1);
                                        skuRelationDao.save(skuRelation);
                                    }
                                }
                            }
                        }
                    }
                }
            }else if(skusLength == 4){
                String spec1 = skus[0];
                if(spec1.contains("+")){
                    String[] specs1 = spec1.split("\\+");
                    String sp1 = specs1[1];
                    if(sp1.contains("_")){
                        String[] ss1 = sp1.split("_");
                        for(int z1 = 0; z1 < ss1.length; z1++){
                            String s1 = ss1[z1];
                            String spec2 = skus[1];
                            if(spec2.contains("+")){
                                String[] specs2 = spec2.split("\\+");
                                String sp2 = specs2[1];
                                if(sp2.contains("_")){
                                    String[] ss2 = sp2.split("_");
                                    for(int z2 = 0; z2 < ss2.length; z2++){
                                        String s2 = ss2[z2];
                                        String spec3 = skus[2];
                                        if(spec3.contains("+")){
                                            String[] specs3 = spec3.split("\\+");
                                            String sp3 = specs3[1];
                                            if(sp3.contains("_")){
                                                String[] ss3 = sp3.split("_");
                                                for(int z3 = 0; z3 < ss3.length; z3++){
                                                    String s3 = ss3[z3];

                                                    String spec4 = skus[3];
                                                    if(spec4.contains("+")){
                                                        String[] specs4 = spec4.split("\\+");
                                                        String sp4 = specs4[1];
                                                        if(sp4.contains("_")){
                                                            String[] ss4 = sp4.split("_");
                                                            for(int z4 = 0; z4 < ss4.length; z4++){
                                                                String s4 = ss4[z4];

                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(s1 + "," + s2 + "," +s3 + "," + s4);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }else{
                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(s1 + "," + s2 + "," + s3 + "," + sp4);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }
                                                }
                                            }else{
                                                String spec4 = skus[3];
                                                if(spec4.contains("+")){
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if(sp4.contains("_")){
                                                        String[] ss4 = sp4.split("_");
                                                        for(int z4 = 0; z4 < ss4.length; z4++){
                                                            String s4 = ss4[z4];

                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(s1 + "," + s2 + "," +sp3 + "," + s4);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }else{
                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3 + "," + sp4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }else{
                                    String spec3 = skus[2];
                                    if(spec3.contains("+")){
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if(sp3.contains("_")){
                                            String[] ss3 = sp3.split("_");
                                            for(int z3 = 0; z3 < ss3.length; z3++){
                                                String s3 = ss3[z3];

                                                String spec4 = skus[3];
                                                if(spec4.contains("+")){
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if(sp4.contains("_")){
                                                        String[] ss4 = sp4.split("_");
                                                        for(int z4 = 0; z4 < ss4.length; z4++){
                                                            String s4 = ss4[z4];

                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(s1 + "," + sp2 + "," +s3 + "," + s4);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }else{
                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(s1 + "," + sp2 + "," + s3 + "," + sp4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }
                                            }
                                        }else{
                                            String spec4 = skus[3];
                                            if(spec4.contains("+")){
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if(sp4.contains("_")){
                                                    String[] ss4 = sp4.split("_");
                                                    for(int z4 = 0; z4 < ss4.length; z4++){
                                                        String s4 = ss4[z4];

                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(s1 + "," + sp2 + "," +sp3 + "," + s4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }else{
                                                    SkuRelation skuRelation = new SkuRelation();
                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                    skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3 + "," + sp4);
                                                    skuRelation.setUpdateTime(new Date());
                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                    skuRelation.setMaximum(1);
                                                    skuRelation.setMinimum(1);
                                                    skuRelationDao.save(skuRelation);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }else{
                        String spec2 = skus[1];
                        if(spec2.contains("+")){
                            String[] specs2 = spec2.split("\\+");
                            String sp2 = specs2[1];
                            if(sp2.contains("_")){
                                String[] ss2 = sp2.split("_");
                                for(int z2 = 0; z2 < ss2.length; z2++){
                                    String s2 = ss2[z2];
                                    String spec3 = skus[2];
                                    if(spec3.contains("+")){
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if(sp3.contains("_")){
                                            String[] ss3 = sp3.split("_");
                                            for(int z3 = 0; z3 < ss3.length; z3++){
                                                String s3 = ss3[z3];

                                                String spec4 = skus[3];
                                                if(spec4.contains("+")){
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if(sp4.contains("_")){
                                                        String[] ss4 = sp4.split("_");
                                                        for(int z4 = 0; z4 < ss4.length; z4++){
                                                            String s4 = ss4[z4];

                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(sp1 + "," + s2 + "," +s3 + "," + s4);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }else{
                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(sp1 + "," + s2 + "," + s3 + "," + sp4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }
                                            }
                                        }else{
                                            String spec4 = skus[3];
                                            if(spec4.contains("+")){
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if(sp4.contains("_")){
                                                    String[] ss4 = sp4.split("_");
                                                    for(int z4 = 0; z4 < ss4.length; z4++){
                                                        String s4 = ss4[z4];

                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(sp1 + "," + s2 + "," +sp3 + "," + s4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }else{
                                                    SkuRelation skuRelation = new SkuRelation();
                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                    skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3 + "," + sp4);
                                                    skuRelation.setUpdateTime(new Date());
                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                    skuRelation.setMaximum(1);
                                                    skuRelation.setMinimum(1);
                                                    skuRelationDao.save(skuRelation);
                                                }
                                            }
                                        }
                                    }
                                }
                            }else{
                                String spec3 = skus[2];
                                if(spec3.contains("+")){
                                    String[] specs3 = spec3.split("\\+");
                                    String sp3 = specs3[1];
                                    if(sp3.contains("_")){
                                        String[] ss3 = sp3.split("_");
                                        for(int z3 = 0; z3 < ss3.length; z3++){
                                            String s3 = ss3[z3];

                                            String spec4 = skus[3];
                                            if(spec4.contains("+")){
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if(sp4.contains("_")){
                                                    String[] ss4 = sp4.split("_");
                                                    for(int z4 = 0; z4 < ss4.length; z4++){
                                                        String s4 = ss4[z4];

                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(sp1 + "," + sp2 + "," +s3 + "," + s4);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }else{
                                                    SkuRelation skuRelation = new SkuRelation();
                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                    skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + s3 + "," + sp4);
                                                    skuRelation.setUpdateTime(new Date());
                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                    skuRelation.setMaximum(1);
                                                    skuRelation.setMinimum(1);
                                                    skuRelationDao.save(skuRelation);
                                                }
                                            }
                                        }
                                    }else{
                                        String spec4 = skus[3];
                                        if(spec4.contains("+")){
                                            String[] specs4 = spec4.split("\\+");
                                            String sp4 = specs4[1];
                                            if(sp4.contains("_")){
                                                String[] ss4 = sp4.split("_");
                                                for(int z4 = 0; z4 < ss4.length; z4++){
                                                    String s4 = ss4[z4];

                                                    SkuRelation skuRelation = new SkuRelation();
                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                    skuRelation.setGroupRelation(sp1 + "," + sp2 + "," +sp3 + "," + s4);
                                                    skuRelation.setUpdateTime(new Date());
                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                    skuRelation.setMaximum(1);
                                                    skuRelation.setMinimum(1);
                                                    skuRelationDao.save(skuRelation);
                                                }
                                            }else{
                                                SkuRelation skuRelation = new SkuRelation();
                                                skuRelation.setProductId(skuSelected.getProductId());
                                                skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3 + "," + sp4);
                                                skuRelation.setUpdateTime(new Date());
                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                skuRelation.setMaximum(1);
                                                skuRelation.setMinimum(1);
                                                skuRelationDao.save(skuRelation);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }else if(skusLength == 5) {
                String spec1 = skus[0];
                if (spec1.contains("+")) {
                    String[] specs1 = spec1.split("\\+");
                    String sp1 = specs1[1];
                    if (sp1.contains("_")) {
                        String[] ss1 = sp1.split("_");
                        for (int z1 = 0; z1 < ss1.length; z1++) {
                            String s1 = ss1[z1];
                            String spec2 = skus[1];
                            if (spec2.contains("+")) {
                                String[] specs2 = spec2.split("\\+");
                                String sp2 = specs2[1];
                                if (sp2.contains("_")) {
                                    String[] ss2 = sp2.split("_");
                                    for (int z2 = 0; z2 < ss2.length; z2++) {
                                        String s2 = ss2[z2];
                                        String spec3 = skus[2];
                                        if (spec3.contains("+")) {
                                            String[] specs3 = spec3.split("\\+");
                                            String sp3 = specs3[1];
                                            if (sp3.contains("_")) {
                                                String[] ss3 = sp3.split("_");
                                                for (int z3 = 0; z3 < ss3.length; z3++) {
                                                    String s3 = ss3[z3];

                                                    String spec4 = skus[3];
                                                    if (spec4.contains("+")) {
                                                        String[] specs4 = spec4.split("\\+");
                                                        String sp4 = specs4[1];
                                                        if (sp4.contains("_")) {
                                                            String[] ss4 = sp4.split("_");
                                                            for (int z4 = 0; z4 < ss4.length; z4++) {
                                                                String s4 = ss4[z4];

                                                                String spec5 = skus[4];
                                                                if (spec5.contains("+")) {
                                                                    String[] specs5 = spec5.split("\\+");
                                                                    String sp5 = specs5[1];
                                                                    if (sp5.contains("_")) {
                                                                        String[] ss5 = sp5.split("_");
                                                                        for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                            String s5 = ss5[z5];

                                                                            SkuRelation skuRelation = new SkuRelation();
                                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                                            skuRelation.setGroupRelation(s1 + "," + s2 + "," + s3 + "," + s4 + "," + s5);
                                                                            skuRelation.setUpdateTime(new Date());
                                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                            skuRelation.setMaximum(1);
                                                                            skuRelation.setMinimum(1);
                                                                            skuRelationDao.save(skuRelation);
                                                                        }
                                                                    } else {
                                                                        SkuRelation skuRelation = new SkuRelation();
                                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                                        skuRelation.setGroupRelation(s1 + "," + s2 + "," + s3 + "," + s4 + "," +sp5);
                                                                        skuRelation.setUpdateTime(new Date());
                                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                        skuRelation.setMaximum(1);
                                                                        skuRelation.setMinimum(1);
                                                                        skuRelationDao.save(skuRelation);
                                                                    }
                                                                }
                                                            }
                                                        } else {
                                                            String spec5 = skus[4];
                                                            if (spec5.contains("+")) {
                                                                String[] specs5 = spec5.split("\\+");
                                                                String sp5 = specs5[1];
                                                                if (sp5.contains("_")) {
                                                                    String[] ss5 = sp5.split("_");
                                                                    for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                        String s5 = ss5[z5];

                                                                        SkuRelation skuRelation = new SkuRelation();
                                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                                        skuRelation.setGroupRelation(s1 + "," + s2 + "," + s3 + "," + sp4 + "," + s5);
                                                                        skuRelation.setUpdateTime(new Date());
                                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                        skuRelation.setMaximum(1);
                                                                        skuRelation.setMinimum(1);
                                                                        skuRelationDao.save(skuRelation);
                                                                    }
                                                                } else {
                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + s2 + "," + s3 + "," + sp4 + "," +sp5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            } else {
                                                String spec4 = skus[3];
                                                if (spec4.contains("+")) {
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if (sp4.contains("_")) {
                                                        String[] ss4 = sp4.split("_");
                                                        for (int z4 = 0; z4 < ss4.length; z4++) {
                                                            String s4 = ss4[z4];

                                                            String spec5 = skus[4];
                                                            if (spec5.contains("+")) {
                                                                String[] specs5 = spec5.split("\\+");
                                                                String sp5 = specs5[1];
                                                                if (sp5.contains("_")) {
                                                                    String[] ss5 = sp5.split("_");
                                                                    for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                        String s5 = ss5[z5];

                                                                        SkuRelation skuRelation = new SkuRelation();
                                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                                        skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3 + "," + s4 + "," + s5);
                                                                        skuRelation.setUpdateTime(new Date());
                                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                        skuRelation.setMaximum(1);
                                                                        skuRelation.setMinimum(1);
                                                                        skuRelationDao.save(skuRelation);
                                                                    }
                                                                } else {
                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3 + "," + s4 + "," +sp5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];
                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3 + "," + sp4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(s1 + "," + s2 + "," + sp3 + "," + sp4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    String spec3 = skus[2];
                                    if (spec3.contains("+")) {
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if (sp3.contains("_")) {
                                            String[] ss3 = sp3.split("_");
                                            for (int z3 = 0; z3 < ss3.length; z3++) {
                                                String s3 = ss3[z3];

                                                String spec4 = skus[3];
                                                if (spec4.contains("+")) {
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if (sp4.contains("_")) {
                                                        String[] ss4 = sp4.split("_");
                                                        for (int z4 = 0; z4 < ss4.length; z4++) {
                                                            String s4 = ss4[z4];

                                                            String spec5 = skus[4];
                                                            if (spec5.contains("+")) {
                                                                String[] specs5 = spec5.split("\\+");
                                                                String sp5 = specs5[1];
                                                                if (sp5.contains("_")) {
                                                                    String[] ss5 = sp5.split("_");
                                                                    for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                        String s5 = ss5[z5];

                                                                        SkuRelation skuRelation = new SkuRelation();
                                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                                        skuRelation.setGroupRelation(s1 + "," + sp2 + "," + s3 + "," + s4 + "," + s5);
                                                                        skuRelation.setUpdateTime(new Date());
                                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                        skuRelation.setMaximum(1);
                                                                        skuRelation.setMinimum(1);
                                                                        skuRelationDao.save(skuRelation);
                                                                    }
                                                                } else {
                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + sp2 + "," + s3 + "," + s4 + "," +sp5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];

                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + sp2 + "," + s3 + "," + sp4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(s1 + "," + sp2 + "," + s3 + "," + sp4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            String spec4 = skus[3];
                                            if (spec4.contains("+")) {
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if (sp4.contains("_")) {
                                                    String[] ss4 = sp4.split("_");
                                                    for (int z4 = 0; z4 < ss4.length; z4++) {
                                                        String s4 = ss4[z4];

                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];

                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3 + "," + s4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3 + "," + s4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    String spec5 = skus[4];
                                                    if (spec5.contains("+")) {
                                                        String[] specs5 = spec5.split("\\+");
                                                        String sp5 = specs5[1];
                                                        if (sp5.contains("_")) {
                                                            String[] ss5 = sp5.split("_");
                                                            for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                String s5 = ss5[z5];

                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3 + "," + sp4 + "," + s5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        } else {
                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(s1 + "," + sp2 + "," + sp3 + "," + sp4 + "," +sp5);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        String spec2 = skus[1];
                        if (spec2.contains("+")) {
                            String[] specs2 = spec2.split("\\+");
                            String sp2 = specs2[1];
                            if (sp2.contains("_")) {
                                String[] ss2 = sp2.split("_");
                                for (int z2 = 0; z2 < ss2.length; z2++) {
                                    String s2 = ss2[z2];
                                    String spec3 = skus[2];
                                    if (spec3.contains("+")) {
                                        String[] specs3 = spec3.split("\\+");
                                        String sp3 = specs3[1];
                                        if (sp3.contains("_")) {
                                            String[] ss3 = sp3.split("_");
                                            for (int z3 = 0; z3 < ss3.length; z3++) {
                                                String s3 = ss3[z3];

                                                String spec4 = skus[3];
                                                if (spec4.contains("+")) {
                                                    String[] specs4 = spec4.split("\\+");
                                                    String sp4 = specs4[1];
                                                    if (sp4.contains("_")) {
                                                        String[] ss4 = sp4.split("_");
                                                        for (int z4 = 0; z4 < ss4.length; z4++) {
                                                            String s4 = ss4[z4];

                                                            String spec5 = skus[4];
                                                            if (spec5.contains("+")) {
                                                                String[] specs5 = spec5.split("\\+");
                                                                String sp5 = specs5[1];
                                                                if (sp5.contains("_")) {
                                                                    String[] ss5 = sp5.split("_");
                                                                    for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                        String s5 = ss5[z5];

                                                                        SkuRelation skuRelation = new SkuRelation();
                                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                                        skuRelation.setGroupRelation(sp1 + "," + s2 + "," + s3 + "," + s4 + "," + s5);
                                                                        skuRelation.setUpdateTime(new Date());
                                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                        skuRelation.setMaximum(1);
                                                                        skuRelation.setMinimum(1);
                                                                        skuRelationDao.save(skuRelation);
                                                                    }
                                                                } else {
                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(sp1 + "," + s2 + "," + s3 + "," + s4 + "," +sp5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            }
                                                        }
                                                    } else {
                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];

                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(sp1 + "," + s2 + "," + s3 + "," + sp4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + s2 + "," + s3 + "," + sp4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            String spec4 = skus[3];
                                            if (spec4.contains("+")) {
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if (sp4.contains("_")) {
                                                    String[] ss4 = sp4.split("_");
                                                    for (int z4 = 0; z4 < ss4.length; z4++) {
                                                        String s4 = ss4[z4];

                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];

                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3 + "," + s4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3 + "," + s4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    String spec5 = skus[4];
                                                    if (spec5.contains("+")) {
                                                        String[] specs5 = spec5.split("\\+");
                                                        String sp5 = specs5[1];
                                                        if (sp5.contains("_")) {
                                                            String[] ss5 = sp5.split("_");
                                                            for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                String s5 = ss5[z5];

                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3 + "," + sp4 + "," + s5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        } else {
                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(sp1 + "," + s2 + "," + sp3 + "," + sp4 + "," +sp5);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            } else {
                                String spec3 = skus[2];
                                if (spec3.contains("+")) {
                                    String[] specs3 = spec3.split("\\+");
                                    String sp3 = specs3[1];
                                    if (sp3.contains("_")) {
                                        String[] ss3 = sp3.split("_");
                                        for (int z3 = 0; z3 < ss3.length; z3++) {
                                            String s3 = ss3[z3];

                                            String spec4 = skus[3];
                                            if (spec4.contains("+")) {
                                                String[] specs4 = spec4.split("\\+");
                                                String sp4 = specs4[1];
                                                if (sp4.contains("_")) {
                                                    String[] ss4 = sp4.split("_");
                                                    for (int z4 = 0; z4 < ss4.length; z4++) {
                                                        String s4 = ss4[z4];

                                                        String spec5 = skus[4];
                                                        if (spec5.contains("+")) {
                                                            String[] specs5 = spec5.split("\\+");
                                                            String sp5 = specs5[1];
                                                            if (sp5.contains("_")) {
                                                                String[] ss5 = sp5.split("_");
                                                                for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                    String s5 = ss5[z5];

                                                                    SkuRelation skuRelation = new SkuRelation();
                                                                    skuRelation.setProductId(skuSelected.getProductId());
                                                                    skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + s3 + "," + s4 + "," + s5);
                                                                    skuRelation.setUpdateTime(new Date());
                                                                    skuRelation.setCostPrice(new BigDecimal(0));
                                                                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                    skuRelation.setRetailPrice(new BigDecimal(0));
                                                                    skuRelation.setParentProfit(new BigDecimal(0));
                                                                    skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                    skuRelation.setMaximum(1);
                                                                    skuRelation.setMinimum(1);
                                                                    skuRelationDao.save(skuRelation);
                                                                }
                                                            } else {
                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + s3 + "," + s4 + "," +sp5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    String spec5 = skus[4];
                                                    if (spec5.contains("+")) {
                                                        String[] specs5 = spec5.split("\\+");
                                                        String sp5 = specs5[1];
                                                        if (sp5.contains("_")) {
                                                            String[] ss5 = sp5.split("_");
                                                            for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                String s5 = ss5[z5];

                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + s3 + "," + sp4 + "," + s5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        } else {
                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + s3 + "," + sp4 + "," +sp5);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    } else {
                                        String spec4 = skus[3];
                                        if (spec4.contains("+")) {
                                            String[] specs4 = spec4.split("\\+");
                                            String sp4 = specs4[1];
                                            if (sp4.contains("_")) {
                                                String[] ss4 = sp4.split("_");
                                                for (int z4 = 0; z4 < ss4.length; z4++) {
                                                    String s4 = ss4[z4];

                                                    String spec5 = skus[4];
                                                    if (spec5.contains("+")) {
                                                        String[] specs5 = spec5.split("\\+");
                                                        String sp5 = specs5[1];
                                                        if (sp5.contains("_")) {
                                                            String[] ss5 = sp5.split("_");
                                                            for (int z5 = 0; z5 < ss5.length; z5++) {
                                                                String s5 = ss5[z5];

                                                                SkuRelation skuRelation = new SkuRelation();
                                                                skuRelation.setProductId(skuSelected.getProductId());
                                                                skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3 + "," + s4 + "," + s5);
                                                                skuRelation.setUpdateTime(new Date());
                                                                skuRelation.setCostPrice(new BigDecimal(0));
                                                                skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                                skuRelation.setRetailPrice(new BigDecimal(0));
                                                                skuRelation.setParentProfit(new BigDecimal(0));
                                                                skuRelation.setAnchorProfit(new BigDecimal(0));
                                                                skuRelation.setMaximum(1);
                                                                skuRelation.setMinimum(1);
                                                                skuRelationDao.save(skuRelation);
                                                            }
                                                        } else {
                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3 + "," + s4 + "," +sp5);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    }
                                                }
                                            } else {
                                                String spec5 = skus[4];
                                                if (spec5.contains("+")) {
                                                    String[] specs5 = spec5.split("\\+");
                                                    String sp5 = specs5[1];
                                                    if (sp5.contains("_")) {
                                                        String[] ss5 = sp5.split("_");
                                                        for (int z5 = 0; z5 < ss5.length; z5++) {
                                                            String s5 = ss5[z5];

                                                            SkuRelation skuRelation = new SkuRelation();
                                                            skuRelation.setProductId(skuSelected.getProductId());
                                                            skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3 + "," + sp4 + "," + s5);
                                                            skuRelation.setUpdateTime(new Date());
                                                            skuRelation.setCostPrice(new BigDecimal(0));
                                                            skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                            skuRelation.setRetailPrice(new BigDecimal(0));
                                                            skuRelation.setParentProfit(new BigDecimal(0));
                                                            skuRelation.setAnchorProfit(new BigDecimal(0));
                                                            skuRelation.setMaximum(1);
                                                            skuRelation.setMinimum(1);
                                                            skuRelationDao.save(skuRelation);
                                                        }
                                                    } else {
                                                        SkuRelation skuRelation = new SkuRelation();
                                                        skuRelation.setProductId(skuSelected.getProductId());
                                                        skuRelation.setGroupRelation(sp1 + "," + sp2 + "," + sp3 + "," + sp4 + "," +sp5);
                                                        skuRelation.setUpdateTime(new Date());
                                                        skuRelation.setCostPrice(new BigDecimal(0));
                                                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                                                        skuRelation.setRetailPrice(new BigDecimal(0));
                                                        skuRelation.setParentProfit(new BigDecimal(0));
                                                        skuRelation.setAnchorProfit(new BigDecimal(0));
                                                        skuRelation.setMaximum(1);
                                                        skuRelation.setMinimum(1);
                                                        skuRelationDao.save(skuRelation);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }else{
            if(sku.contains("+")){
                String[] specs1 = sku.split("\\+");
                String sp1 = specs1[1];
                if(sp1.contains("_")){
                    String[] ss1 = sp1.split("_");
                    for(int z1 = 0; z1 < ss1.length; z1++){
                        String s1 = ss1[z1];
                        SkuRelation skuRelation = new SkuRelation();
                        skuRelation.setProductId(skuSelected.getProductId());
                        skuRelation.setGroupRelation(s1);
                        skuRelation.setUpdateTime(new Date());
                        skuRelation.setCostPrice(new BigDecimal(0));
                        skuRelation.setDeliveryPrice(new BigDecimal(0));
                        skuRelation.setRetailPrice(new BigDecimal(0));
                        skuRelation.setParentProfit(new BigDecimal(0));
                        skuRelation.setAnchorProfit(new BigDecimal(0));
                        skuRelation.setMaximum(1);
                        skuRelation.setMinimum(1);
                        skuRelationDao.save(skuRelation);
                    }
                }else{
                    SkuRelation skuRelation = new SkuRelation();
                    skuRelation.setProductId(skuSelected.getProductId());
                    skuRelation.setGroupRelation(sp1);
                    skuRelation.setUpdateTime(new Date());
                    skuRelation.setCostPrice(new BigDecimal(0));
                    skuRelation.setDeliveryPrice(new BigDecimal(0));
                    skuRelation.setRetailPrice(new BigDecimal(0));
                    skuRelation.setParentProfit(new BigDecimal(0));
                    skuRelation.setAnchorProfit(new BigDecimal(0));
                    skuRelation.setMaximum(1);
                    skuRelation.setMinimum(1);
                    skuRelationDao.save(skuRelation);
                }
            }
        }
    }

}
